import {Injectable} from '@angular/core';
import {ParkingCharge} from '../types/resp/ParkingCharge';
import {ParkingChargeForm} from '../types/req/ParkingChargeForm';
import {Result} from '../types/result';
import MockApi from '../api/mockApi';
import {map, Observable} from 'rxjs';
import type {Response} from '../types/response';
import {Page} from '../types/page';
import {ParkingChargeQueryForm} from '../types/req/ParkingChargeQueryForm';

@Injectable({
  providedIn: 'root'
})
export class ParkingChargeService {
  parkingCharges: ParkingCharge[] = [
    {id: 1, parkingAreaId: 1, parkingAreaNumber: '010', residentRoomId: 1, residentRoomNumber: '201', licensePlate: '粤A11111', billingStartDate: '2024-01-01', billingEndDate: '2024-01-31', amount: 32.54, remark: '1月车位费', createTime: '2024-02-02 13:13:13'},
    {id: 2, parkingAreaId: 2, parkingAreaNumber: '021', residentRoomId: 2, residentRoomNumber: '302', licensePlate: '粤A11112', billingStartDate: '2024-02-01', billingEndDate: '2024-02-29', amount: 43.54, remark: '2月车位费', createTime: '2024-03-03 13:13:13'},
    {id: 3, parkingAreaId: 3, parkingAreaNumber: '032', residentRoomId: 3, residentRoomNumber: '403', licensePlate: '粤A11113', billingStartDate: '2024-03-01', billingEndDate: '2024-03-31', amount: 74.54, remark: '3月车位费', createTime: '2024-04-04 13:13:13'},
    {id: 4, parkingAreaId: 4, parkingAreaNumber: '019', residentRoomId: 4, residentRoomNumber: '503', licensePlate: '粤A11114', billingStartDate: '2024-03-01', billingEndDate: '2024-03-31', amount: 54.54, remark: '3月车位费', createTime: '2024-04-04 13:13:13'},
    {id: 5, parkingAreaId: 5, parkingAreaNumber: '043', residentRoomId: 5, residentRoomNumber: '604', licensePlate: '粤A11115', billingStartDate: '2024-04-01', billingEndDate: '2024-04-30', amount: 65.54, remark: '4月车位费', createTime: '2024-05-05 13:13:13'}
  ]
  constructor() {
  }

  save (parkingChargeForm: ParkingChargeForm): Observable<Result<void>> {
    console.log('parkingChargeApi save params', parkingChargeForm)
    return MockApi.operateSuccessfully().pipe(
      map((response: Response<Result<void>>) => response.data)
    );
  }

  find (parkingChargeQueryForm: ParkingChargeQueryForm): Observable<Result<Page<ParkingCharge>>> {
    console.log('parkingChargeApi find params', parkingChargeQueryForm)
    return MockApi.queryPageSuccessfully(this.parkingCharges).pipe(
      map((response: Response<Result<Page<ParkingCharge>>>) => response.data)
    );
  }

  findById (id: number): Observable<Result<ParkingCharge>> {
    console.log('parkingChargeApi findById id', id)
    let target = {}
    for (const a of this.parkingCharges) {
      if (a.id === id) {
        target = a
      }
    }
    return MockApi.operateSuccessfullyWithData(target).pipe(
      map((response: Response<Result<ParkingCharge>>) => response.data)
    );
  }

  del (id: number): Observable<Result<void>> {
    console.log('parkingChargeApi del id', id)
    return MockApi.operateSuccessfully().pipe(
      map((response: Response<Result<void>>) => response.data)
    );
  }
}
